<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>个人中心</title>
    <script src="js/rem.js"></script>
    <link rel="stylesheet" href="css/weui.min.css">
    <link rel="stylesheet" href="css/jquery-weui.min.css">
    <link rel="stylesheet" href="css/public.css">
    <link rel="stylesheet" href="css/user.css">
    <script>(function() {var _53code = document.createElement("script");_53code.src = "https://tb.53kf.com/code/code/96d8f960b261e49515450f8953b044bc5/1";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(_53code, s);})();</script>
</head>
<body>
    <div class="user user-share hide j_share" id="j_share">
        <div class="container">
            <div class="info-box">
            </div>
        </div>
    </div>
    <div class="user user-share hide j_share">
        <div class="container">
            <div class="info-box">
            </div>
            <p class="tip2">出示二维码面对面邀请医生</p>
            <div class="j_no_poster">
                <div class="save-box">
                    <button class="save-btn">生成海报</button>
                </div>
                <div class="sw-hr">分享至</div>
                <div class="wechat-box">
                    <img class="wechat-i1 j_share_w" src="image/share-wechat-i.png" alt="">
                </div>
            </div>
        </div>
    </div>
    <!-- 海报弹窗 -->
    <div class="poster popup">
        <div class="cont">
            <img class="poster-img" src="" alt="">
            <p class="tip">长按图片保存到相册</p>
        </div>
    </div>
    <!-- 提示分享弹窗 -->
    <div class="share popup">
        <div class="cont">
            <img class="arrow-r" src="image/arrow-right.png" alt="">
            <p class="tip">点击这里分享</p>
        </div>
    </div>
    <!-- <img class="user user-share hide poster-img j_share" src="" alt=""> -->
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/jweixin-1.6.0.js"></script>
    <script src="js/jquery-weui.min.js"></script>
    <script src="js/html2canvas.js"></script>
    <script src="js/md5.js"></script>
    <script src="js/public.js"></script>
    <script>
        // 查询我的认证
        var shareUrl;
        var userId = getCookie('userId');
        if(userId){
            queryShareInfo();
        }else {
            window.location.href = 'login-code.html'
        }
        $(document.body).on('click', '.j_share_w', function(){
            $('.share.popup').show();
        })
        $(document.body).on('click', '.save-btn', function(){
            $.showLoading('海报生成中...')
            html2canvas(document.querySelector("#j_share"), {
                dpi: 300,
                allowTaint: true, 
                useCORS: true 
            }).then(canvas => {
                var url = canvas.toDataURL('image/png');
                $('.poster.popup').show().find('.poster-img').attr('src', url);
                $.hideLoading();
            });
        })
        function queryShareInfo(){
            http('/user/getShareCode', {
                loading: true,
                hasToken: false,
                data: {
                    userId: userId
                },
                success: function(res){
                    if(res.code === '01'){
                        var data = res.data;
                        var head = data.head ? data.head : 'image/share-avatar.png';
                        var html = '<img class="avatar-img" src="' + head + '" alt="">' + 
                            '<p class="nickname">' + data.nickName + '</p>' + 
                            '<p class="share-code">邀请码:' + data.shareCode + '</p>' + 
                            '<div>' + 
                                '<div class="shere-code-box">' + 
                                    '<a href="' + data.goUrl + '">' + 
                                        '<img class="j_code_img" src="' + host + data.qrUrl + '" alt="">' +  
                                    '</a>' + 
                                '</div>' + 
                            '</div>' + 
                            '<p class="tip">长按识别二维码</p>';
                        shareUrl = host + data.goUrl;
                        $('.info-box').html(html)
                        $('.j_share').show();
                    }
                }
            })
        }
        
        var getBas64 = function(url, fn){
            var canvas = document.createElement('CANVAS'),
                ctx = canvas.getContext('2d'),
                img = new Image();

                img.setAttribute('crossOrigin', 'anonymous');// 重点！设置image对象可跨域请求
                img.onload = function () {
                    canvas.height = img.height;
                    canvas.width = img.width;
                    ctx.drawImage(img, 0, 0);
                    let dataURL = canvas.toDataURL('image/png');
                    canvas = null;
                    fn(dataURL);
                };
                img.src = url;
        }
        xcxConfig2();
        function xcxConfig2() {
            //初始化微信分享参数--开始
            var wxappid = "";
            var timestamp = "";
            var nonceStr = "";
            var signature = "";
            initWxShareParams();
            function initWxShareParams() {
                var requestUrl = window.location.href;
                $.ajaxSetup({
                    async: false,
                });
                http('/user/getSign', {
                    hasToken: false,
                    data: {
                        "url": requestUrl
                    },
                    success: function(res){
                        if(res.code === '01'){
                            var iData = res.data;
                            wxappid = iData.appid;
                            timestamp = iData.timestamp;
                            nonceStr = iData.noncestr;
                            signature = iData.signature;

                            //微信分享--开始
                            wx.config({
                                debug: false,
                                appId: wxappid,
                                timestamp: timestamp,
                                nonceStr: nonceStr,
                                signature: signature,
                                jsApiList: [
                                    'onMenuShareTimeline',
			                        'onMenuShareAppMessage'
                                ],
                                openTagList: ['wx-open-launch-weapp']
                            });
                            wx.ready(function() {
                                var wxtitle = '名医讲习所', 
                                    wxdesc = '名医讲习所',
                                    imgShareUrl = host + dir + '/image/share-bg.png';

                                wx.onMenuShareAppMessage({
                                    title: wxtitle, // 分享标题
                                    desc: wxdesc, // 分享描述
                                    imgUrl: imgShareUrl, // 分享图标
                                    link: shareUrl, // 分享链接
                                    success: function() {
                                    },
                                    cancel: function() {
                                        // 用户取消分享后执行的回调函数
                                    }
                                });
                            
                                wx.onMenuShareTimeline({
                                    title: wxtitle, // 分享标题
                                    desc: wxdesc, // 分享描述
                                    imgUrl: imgShareUrl, // 分享图标
                                    link: shareUrl, // 分享链接
                                    success: function() {
                                    },
                                    cancel: function() {
                                        // 用户取消分享后执行的回调函数
                                    }
                                });
                            });
                        }
                    }
                })
            }
        }
    </script>
</body>
</html>